package com.authService.controller;

import com.authService.pojo.req.RolePageReqDTO;
import com.authService.pojo.req.RoleSaveReqDTO;
import com.authService.pojo.res.RoleDetialResDTO;
import com.authService.pojo.res.RolePageResDTO;
import com.authService.service.ISysRoleService;
import com.xiaopeng.common.httpResult.model.HttpResult;
import com.xiaopeng.common.page.PageVO;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author xiaopeng
 * @since 2024-10-21
 */
@Controller
@RequestMapping("/role")
public class SysRoleController {

    @Resource
    private ISysRoleService sysRoleService;

    @Operation(summary = "系统角色-分页查询")
    @PostMapping("/page")
    public HttpResult<PageVO<RolePageResDTO>> selectPage(@RequestBody RolePageReqDTO reqDTO) {
        return HttpResult.success(sysRoleService.selectPage(reqDTO));
    }

    @Operation(summary = "系统角色-详情")
    @GetMapping("/detail")
    public HttpResult<RoleDetialResDTO> detail(@RequestParam Long roleId) {
        return HttpResult.success(sysRoleService.detail(roleId));
    }

    @Operation(summary = "系统角色-保存")
    @PostMapping("/save")
    public HttpResult<Void> save(@RequestBody @Valid RoleSaveReqDTO reqDTO) {
        sysRoleService.saveRole(reqDTO);
        return HttpResult.success();
    }

    @Operation(summary = "系统角色-修改")
    @PostMapping("/update")
    public HttpResult<Void> update(@RequestBody @Valid RoleSaveReqDTO reqDTO) {
        sysRoleService.updateRole(reqDTO);
        return HttpResult.success();
    }

}
